package com.tang.campus_market.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.tang.campus_market.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {
    @Select("SELECT * FROM market_user WHERE email=#{email}")
    public User getInfoFromEmail(@Param("email") String email);

    @Select("SELECT * FROM market_user WHERE phone_number=#{phoneNumber}")
    User getInfoFromphoneNumber(@Param("phoneNumber") String phoneNumber);


    @Select("SELECT * FROM market_user WHERE nick_name=#{name}")
    User getInfoFromName(@Param("name") String name);

    @Select("select id,nick_name,phone_number,email,sex,create_date,state from market_user")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "nickName",column = "nick_name"),
            @Result(property = "phoneNumber",column = "phone_number"),
            @Result(property = "email",column = "email"),
            @Result(property = "sex",column = "sex"),
            @Result(property = "createDate",column = "create_date"),
            @Result(property = "state",column = "state")
    })
    List<User> findAll();

    @Update("update market_goods set state=0 where user_id = #{id}")
    void updateGoodsStateById(Integer id);

    @Update("update market_comment set state=0 where user_id = #{id}")
    void updateCommentStateById(Integer id);

    @Update("update market_order set status=0 where seller_id = #{id}")
    void updateOrderById(Integer id);

    @Update("update market_user set state=0 where id = #{id}")
    void updateUserById(Integer id);

    @Update("update market_goods set state=1 where user_id = #{id}")
    void activeGoodsStateById(Integer id);

    @Update("update market_comment set state=1 where user_id = #{id}")
    void activeCommentStateById(Integer id);

    @Update("update market_order set status=1 where seller_id = #{id}")
    void activeOrderById(Integer id);

    @Update("update market_user set state=1 where id = #{id}")
    void activeUserById(Integer id);

    @Select("select * from market_user where email = #{email} and password = #{password}")
    User selectUserByEmailAndPassword(@Param("email") String email,@Param("password") String password);
}
